package com.demo.lengthFieldBasedFrameDecoder.demo1;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.StandardCharsets;

/**
 * @Description:
 * @Author: rosh
 * @Date: 2022/6/9 22:15
 */
@Slf4j
public class MySimpleChannelInboundHandler extends SimpleChannelInboundHandler<ByteBuf> {
    private int count = 0;
    //前面的数据length把长度域跳过了，这里就是正式的数据了
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        count++;
        log.info("服务端第:{} 次收到消息，消息内容为:{}", count, msg.toString(StandardCharsets.UTF_8));
    }
}
